package com.flyox.game.militarychess.server.services;

import java.util.Hashtable;

import com.flyox.game.militarychess.CONSTS;
import com.flyox.game.militarychess.bean.Player;
import com.flyox.game.militarychess.server.services.data.SystemInfo;

public class PlayerService {

	SystemInfo systemInfo=new SystemInfo();
	/**
	 * 取得所有用户信息
	 * @return
	 */
	public Hashtable<String, Player> getPlayers() {
		return systemInfo.getPlayers();
	}
	
	/**
	 * 取得一个玩家信息
	 * @param id
	 * @return
	 */
	public Player getPlayer(String id) {
		if(id==null||id.length()!=40){
			return null;
		}
		return systemInfo.getPlayers().get(id);
	}
	
	/**
	 * 添加一个玩家
	 * @param player
	 * @return
	 */
	public boolean addPlayer(Player player){
		if (getPlayers().containsKey(player.getId())) {
			return false;
		} else {
			getPlayers().put(player.getId(), player);
			return true;
		}
	}
	
	/**
	 * 删除一个玩家
	 * @param playerID
	 * @return
	 */
	public boolean removePlayer(String playerID){
		if(playerID==null||playerID.length()!=40){
			return false;
		}
		systemInfo.getPlayers().remove(playerID);
		return true;
	}
	
	public int getPlayerState(String playerID){
		if(getPlayer(playerID)!=null){
			return getPlayer(playerID).getStates();
		}else{
			return CONSTS.PLAYER_STATS_NOLOGIN;
		}
	}
}
